package top.suyarong.ftbqsync.utils;

import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

public class LogUtil {

    private static final FormatUtil format = FormatUtil.getInstance();

    private LogUtil() {
    }

    private static volatile LogUtil instance;

    public static synchronized LogUtil getInstance() {
        if (instance == null) {
            synchronized (LogUtil.class) {
                if (instance == null) {
                    instance = new LogUtil();
                }
            }
        }
        return instance;
    }

    /**
     * debug日志
     *
     * @param plugin  log插件
     * @param message 消息
     * @param args    占位符
     */
    public void debug(Plugin plugin, String message, Object... args) {
        if (ConfigReader.isNotDebug()) return;
        plugin.getLogger().info("[debug]" + format.formatPlaceMessage(format.formatColor(message), args));
    }


    /**
     * 日志
     *
     * @param plugin  log插件
     * @param message 消息
     * @param args    占位符
     */
    public void info(Plugin plugin, String message, Object... args) {
        plugin.getLogger().info(format.formatPlaceMessage(format.formatColor(message), args));
    }

    /**
     * 警告日志
     *
     * @param plugin  log插件
     * @param message 消息
     * @param args    占位符
     */
    public void warn(Plugin plugin, String message, Object... args) {
        plugin.getLogger().warning(ChatColor.YELLOW + format.formatPlaceMessage(message, args));
    }

    /**
     * 错误日志
     *
     * @param plugin  log插件
     * @param message 消息
     * @param args    占位符
     */
    public void error(Plugin plugin, String message, Object... args) {
        plugin.getLogger().warning(ChatColor.RED + format.formatPlaceMessage(message, args));
    }

    /**
     * 向玩家发送信息
     *
     * @param player  玩家
     * @param message 消息 需要手动设置颜色&
     * @param args    占位符
     */
    public void message(Player player, String message, Object... args) {
        player.sendMessage(format.formatColor(format.formatPlaceMessage(message, args)));
    }

    /**
     * 向玩家发送滚动条 (VexView)
     * @param player 玩家
     * @param message 消息 需要手动设置颜色&
     * @param args 占位符

    public void sendFlow(Player player, String message, Object... args) {
    String flow = format.formatColor(format.formatPlaceMessage(message, args));
    VexViewAPI.sendFlowView(player, flow, 5, true);
    }
     */


}
